package com.kai.steering.common.web.vo;

import com.kai.steering.exception.UimpException;
import org.springframework.http.HttpStatus;

/**
 * @ Author     ：LiuKai.
 * @ Date       ：Created in 10:54 2022-2-22
 * @ Description：web响应码
 * @ Modified By：
 * @Version:
 */
public enum ReturnCodeExt {

    VERIFICATION_CODE(HttpStatus.BAD_REQUEST, "4201", "验证码校验异常.%s"),
    PARAMETER_PARSE(HttpStatus.BAD_REQUEST, "4100", "参数解析异常.%s"),
    PARAMETER_CHECK(HttpStatus.BAD_REQUEST, "4200", "参数校验失败.%s"),
    AUTHENTICATION_EXCEPTION(HttpStatus.BAD_REQUEST, "4300", "登陆授权异常.%s"),

    SYSTEM_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "5100", "系统处理异常.%s"),
    BUSINESS_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "5200", "业务处理异常.%s"),
    DAO_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "5300", "数据库处理异常.%s"),
    FEIGN_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "5400", "feign 调用异常.STATE[%s] BODY[%s]"),
    SYSTEM_OTHER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "5900", "系统其他异常[%s].%s"),;

    private HttpStatus httpStatus;
    private final String code;
    private final String msg;

    ReturnCodeExt(HttpStatus httpStatus, final String code, final String msg) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public HttpStatus getHttpStatus() {
        return httpStatus;
    }

    public UimpException getException(HttpStatus status, Throwable ex, String... pram) {
        String message = (pram == null) ? this.msg : String.format(this.msg, pram);
        if (status == null) {
            status = this.httpStatus;
        }
        return new UimpException(status, this.code, message, ex);
    }

    public UimpException getException(Throwable ex, String... pram) {
        return getException(null, ex, pram);
    }

    public UimpException getException(String... pram) {
        return getException(null, pram);
    }


}

